package cn.xd.common.domain.auth;

import cn.xd.common.enums.IBaseEnum;
import cn.xd.common.enums.auth.AppTypeEnum;
import cn.xd.common.enums.auth.AppUserTypeEnum;
import cn.xd.common.enums.auth.UserSourceEnum;
import cn.xd.common.enums.auth.UserTypeEnum;
import lombok.Getter;
import lombok.Setter;

/**
 * @author : mirzaLin
 * @data : 2023/11/21
 * @description : 当前用户信息基类
 **/
@Setter
public class CurrentUser {
    @Getter
    private Long id;

    private Integer type;
    private String source;

    public UserSourceEnum getUserSource() {
        return IBaseEnum.getEnumByCode(source, UserSourceEnum.class);
    }

    public AppUserTypeEnum getAppUserType() {
        return IBaseEnum.getEnumByCode(type, AppUserTypeEnum.class);
    }

    public AppTypeEnum getAppType() {
        return getAppUserType().getAppTypeEnum();
    }

    public UserTypeEnum getUserType() {
        return getAppUserType().getUserTypeEnum();
    }

    /**
     * 获得使用者用户id，不为使用者返回null
     *
     * @return
     */
    public Long getCustomerUserId() {
        if (getUserType().equals(UserTypeEnum.CUSTOMER)) {
            return id;
        } else {
            return null;
        }
    }

    /**
     * 获得管理者用户id，不为使用者返回null
     *
     * @return
     */
    public Long getAdminUserId() {
        if (getUserType().equals(UserTypeEnum.ADMIN)) {
            return id;
        } else {
            return null;
        }
    }
}
